/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jule.clases;

// para xtream...
import com.thoughtworks.xstream.XStream;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.*;     // para ArrayList..
import java.util.logging.Level;
import java.util.logging.Logger;
import jule.JuleView;

/**
 *
 * @author Administrador
 */
public class project {

    // tipos de database que aceptamos...
    public enum dbDataType {
        MySql, PostgreSql, SqlServer,Jdbc,SqlExpress
    
    }
    
    private String _nombre;

    public String getName() {
        return _nombre;
    }

    public void setNombre(String d) {
        _nombre = d;
    }
    private String _applicationDirectory;

    public String getApplicationDirectory() {
        return _applicationDirectory;
    }

    public void setApplicationDirectory(String d) {
        _applicationDirectory = d;
    }
    private String _database;

    public String getdatabase() {
        return _database;
    }

    public void setdatabase(String d) {
        _database = d;
    }

    private String _instance;

    public String getInstance() {
        return _instance;
    }

    public void setInstance(String d) {
        _instance = d;
    }


    private String _user;

    public String getuser() {
        return _user;
    }

    public void setuser(String d) {
        _user = d;
    }
    private String _password;

    public String getpassword() {
        return _password;
    }

    public void setpassword(String d) {
        _password = d;
    }
    private String _host;

    public String getHost() {
        return _host;
    }

    public void setHost(String d) {
        _host = d;
    }
    
    
        protected String description;

    /**
     * Get the value of description
     *
     * @return the value of description
     */
    public String getDescription() {
        return description;
    }

    /**
     * Set the value of description
     *
     * @param description new value of description
     */
    public void setDescription(String description) {
        this.description = description;
    }

    
    
    private ArrayList<table> _tablas;

    public ArrayList<table> getTables() {
        return _tablas;
    }

    public void setTablas(ArrayList<table> d) {
        _tablas = d;
    }
    private ArrayList _foreignKeys;

    public ArrayList getForeignKeys() {
        return _foreignKeys;
    }

    public void setForeignKeys(ArrayList d) {
        _foreignKeys = d;
    }
    
    
    private dbDataType _typeOfDataBase;

    public dbDataType getTypeOfDataBase() {
        return _typeOfDataBase;
    }
        

    public void setTypeOfDataBase(dbDataType d) {
        _typeOfDataBase = d;
    }
    private String _port;

    public String getPort() {
        return _port;
    }

    public void setPort(String d) {
        _port = d;
    }

    public String toString() {
        return this.getName();
    }

    
        protected String projectTemplatesDirectory;

    /**
     * Get the value of projectTemplatesDirectory
     *
     * @return the value of projectTemplatesDirectory
     */
    public String getProjectTemplatesDirectory() {
        return projectTemplatesDirectory;
    }

    /**
     * Set the value of projectTemplatesDirectory
     *
     * @param projectTemplatesDirectory new value of projectTemplatesDirectory
     */
    public void setProjectTemplatesDirectory(String projectTemplatesDirectory) {
        this.projectTemplatesDirectory = projectTemplatesDirectory;
    }

    
     

    
    
    
    public void saveProject(project pro) throws Exception {

        // inicializamos por si acaso...
        util ut = new util();

        XStream xstream = new XStream();
       // xstream.alias("project", project.class);
        String theXml = xstream.toXML(pro);

        String archivo = ut.projectsDirectory + ut.fileSeparator + pro.getName() + ".ule";
        PrintWriter pw = new PrintWriter(new FileWriter(archivo));
        pw.println(theXml);
        pw.flush();
        pw.close();
    }

    public static project loadProject(String file) throws Exception {
        try {
            XStream xstream = new XStream();
            BufferedReader reader = new BufferedReader(new FileReader(file ));
            
            String theXml = "";
            theXml=util.readFileAsString(file);


            project pro = (project) xstream.fromXML(theXml);
            return pro;
        } catch (Exception ex) {
            Logger.getLogger(JuleView.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }




    }
} // fin de class project

//   // Creates an ArrayList to store each object, and 
//       // adds each object with the add method and dot operator
//       // as well as with the arguments for each object.
//       
//       ArrayList items = new ArrayList();
//       items.add(new ItemsListing("Snorkel"));
//       items.add(new ItemsListing("Diving Mask"));
//       items.add(new ItemsListing("6.5 mm Wet Suit"));
//       
//      // The ArrayList is then passed to an Iterator
//      
//       Iterator iterateItems = items.iterator();
//       
//      // while loops through each element of the ArrayList
//      // and prints the results 
//      
//       while (iterateItems.hasNext()) {
//           System.out.println(iterateItems.next());
//       }
